<!-- f r o m 7 5  2 7 1  8 9 2 0 -->
<template>
  <a-row :gutter="24">
    <a-col :md="24">
      <a-card :style="cardStyle" :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <!-- 搜索区域 -->
          <a-form layout="inline" @keyup.enter.native="searchQuery">
            <a-row :gutter="24">
              <a-col :md="6" :sm="24">
                <a-form-item label="客户名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input placeholder="请输入名称查询" v-model="queryParam.customerName"></a-input>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item label="所属行业" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input placeholder="请输入所属行业查询" v-model="queryParam.industry"></a-input>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item label="报价时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-range-picker
                    style="width: 100%"
                    :placeholder="['开始时间', '结束时间']"
                    v-model="queryParam.quotationDate"
                    @change="quotationDateFromat"
                    format="YYYY-MM-DD"
                  />
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item label="业务负责人" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <!-- <a-input placeholder="请输入业务负责人查询" v-model="queryParam.businessOwner"></a-input> -->
                  <a-select
                    :disabled="disable"
                    v-model="queryParam.businessOwner"
                    allowClear
                    placeholder="选择业务负责人"
                    showSearch
                    optionFilterProp="children"
                  >
                    <a-select-option v-for="(item, index) in personList" :key="index" :value="item">
                      {{ item }}
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                <a-col :md="6" :sm="24">
                  <a-button type="primary" @click="searchQuery">查询</a-button>
                  <a-button style="margin-left: 8px" @click="searchReset">重置</a-button>
                </a-col>
              </span>
            </a-row>
          </a-form>
        </div>
        <!-- 操作按钮区域 -->
        <div class="table-operator" style="margin: 5px 0px">
          <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
        </div>
        <!-- table区域-begin -->
        <div>
          <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="id"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :scroll="{ x: 1600 }"
            :loading="loading"
            :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
            @change="handleTableChange"
          >
            <span slot="action" slot-scope="text, record">
              <a @click="handleEdit(record)">编辑</a>
              <a-divider type="vertical" />
              <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                <a>删除</a>
              </a-popconfirm>
            </span>
            <span slot="quotationForm" slot-scope="text, record">
              <!-- <a @click="myhandleExportXls('报价记录表', record)">下载</a>
              <a-divider type="vertical" /> -->
              <a @click="previewFileList(record)">记录列表</a>
            </span>
            <!-- 状态渲染模板 -->
            <template slot="customRenderFlag" slot-scope="enabled">
              <a-tag v-if="enabled" color="green">启用</a-tag>
              <a-tag v-if="!enabled" color="orange">禁用</a-tag>
            </template>
          </a-table>
        </div>
        <!-- table区域-end -->
        <!-- 表单区域 -->
        <OfferListModal ref="modalForm" @ok="modalFormOk"></OfferListModal>
        <QuotationList ref="modalFormFile" @ok="modalFormOk"></QuotationList>
      </a-card>
    </a-col>
  </a-row>
</template>
<!-- BY cao_yu_li -->
<script>
import OfferListModal from './modules/OfferListModal'
import { personList } from '@/api/api'
import QuotationList from './modules/QuotationList'
import { getActionImg, downFile } from '@/api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { openDownloadDialog, sheet2blob } from '@/utils/util'
import JDate from '@/components/jeecg/JDate'
export default {
  name: 'OfferList',
  mixins: [JeecgListMixin],
  components: {
    OfferListModal,
    QuotationList,
    JDate
  },
  data() {
    return {
      personList: [],
      disable: false,
      labelCol: {
        span: 5
      },
      wrapperCol: {
        span: 18,
        offset: 1
      },
      quotationDate: null,
      // 查询条件
      queryParam: {},
      ipagination: {
        pageSizeOptions: ['10', '20', '30', '100', '200']
      },
      // 表头
      columns: [
        // {
        //   title: '#',
        //   dataIndex: '',
        //   key:'rowIndex',
        //   width:60,
        //   align:"center",
        //   customRender:function (t,r,index) {
        //     return parseInt(index)+1;
        //   },
        //   fixed: 'left'
        // },
        { title: '客户名称', dataIndex: 'customerName', key: '1', width: 150, align: 'center' },
        { title: '所属行业', dataIndex: 'industry', key: '2', width: 100, align: 'center' },
        { title: '业务负责人', dataIndex: 'businessOwner', key: '6', width: 100, align: 'center' },
        { title: '产品名称', dataIndex: 'productName', key: '3', width: 150, align: 'center' },
        { title: '报价时间', dataIndex: 'quotationDate', key: '4', width: 150, align: 'center' },
        {
          title: '报价记录表',
          dataIndex: 'quotationForm',
          key: '5',
          width: 150,
          align: 'center',
          scopedSlots: { customRender: 'quotationForm' }
        },
        {
          title: '操作',
          dataIndex: 'action',
          key: '12',
          width: 100,
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/quotationRecord/searchList',
        delete: '/quotationRecord/remove',
        deleteBatch: '/supplier/deleteBatch',
        importExcelUrl: '/supplier/importCustomer',
        exportXlsUrl: '/systemConfig/static',
        batchSetStatusUrl: '/supplier/batchSetStatus'
      }
    }
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}${this.url.importExcelUrl}`
    }
  },
  mounted() {
    //判断全部还是个人数据
    this.filterData()
    personList().then(res => {
      if (res.code == 200 || res.code == 10000) {
        this.personList = res.data
      } else {
        this.$message.warning(res.message)
      }
    })
  },
  methods: {
    filterData() {
      let a = JSON.parse(sessionStorage.getItem('UserMessage'))
      let useMsg = JSON.parse(sessionStorage.getItem('User'))
      if (a) {
        this.queryParam.businessOwner = useMsg.ename
        this.disable = true
        console.log(this.queryParam.applicant, 'this.queryParam.applicant')
      } else {
        this.disable = false
      }
    },
    //报价记录列表
    previewFileList(record) {
      this.$refs.modalFormFile.edit(record)
    },
    previewFile(fileName, record) {
      if (record && record.quotationForm) {
        let params = record.quotationForm
        getActionImg('systemConfig/preview/' + params).then(res => {
          const binaryData = []
          binaryData.push(res)
          window.open(window.URL.createObjectURL(new Blob(binaryData, { type: 'application/pdf' })))
        })
      }
    },
    myhandleExportXls(fileName, record) {
      if (!fileName || typeof fileName != 'string') {
        fileName = '导出文件'
      }
      downFile(this.url.exportXlsUrl + '/' + record.quotationForm).then(data => {
        if (!data) {
          this.$message.warning('文件下载失败')
          return
        }
        if (typeof window.navigator.msSaveBlob !== 'undefined') {
          window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), fileName + '.xls')
        } else {
          let url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }))
          let link = document.createElement('a')
          link.style.display = 'none'
          link.href = url
          link.setAttribute('download', fileName + '.xls')
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link) //下载完成移除元素
          window.URL.revokeObjectURL(url) //释放掉blob对象
        }
      })
    },
    //修改时间格式
    quotationDateFromat: function(value, dateString) {
      this.queryParam.startTime = dateString[0]
      this.queryParam.endTime = dateString[1]
      console.log(this.queryParam)
    },
    handleEdit: function(record) {
      this.$refs.modalForm.edit(record)
      this.$refs.modalForm.title = '编辑'
      this.$refs.modalForm.disableSubmit = false
      if (this.btnEnableList.indexOf(1) === -1) {
        this.$refs.modalForm.isReadOnly = false
      }
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
